package com;

import com.fz.entity.StuClass;
import com.fz.entity.Student;
import com.fz.entity.Teacher;
import com.fz.mapper.MemberMapper;
import com.fz.mapper.StudentMapper;
import com.fz.mapper.TeacherMapper;
import com.fz.mybatis.MyHelper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017-08-28.
 */
public class Demo {

    @Test
    public void up(){
        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        StudentMapper sdao = s.getMapper(StudentMapper.class);
        Map<String,Object> m = new HashMap<String,Object>();
        m.put("score",100);
        //m.put("id",41);
        m.put("ids",new int[]{33,39,45});
        sdao.updateScore(m);
        s.commit();

    }


    @Test
    public void del(){
        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        StudentMapper sdao = s.getMapper(StudentMapper.class);
        Map<String,Object> m = new HashMap<String,Object>();
        //m.put("id",24);
        m.put("ids",new int[]{36,37});
        //m.put("name","李丽");
        sdao.delete(m);
        //sdao.delete();
        //sdao.deleteById(38);
        //sdao.deleteByName("李%");
        s.commit();

    }
    @Test
    public void upd(){
        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        StudentMapper sdao = s.getMapper(StudentMapper.class);
        Map<String,Object> m = new HashMap<String,Object>();
        //m.put("id",21);
        //m.put("name","吴刚");
        //m.put("score",99);
        //m.put("address","开封");
        //m.put("score",1);

        //sdao.update(m);
        sdao.updateInc(3);
        s.commit();

    }


    @Test
    public void abc() {
        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        StudentMapper sdao = s.getMapper(StudentMapper.class);
        Map<String,Object> m = new HashMap<String,Object>();
        //m.put("name","%丽%");
        m.put("address","北京");
        //m.put("name","李丽");
        //m = null;
        List<Student> sss = sdao.search(m);
        System.out.println(sss);
    }

    @Test
    public void mm() {


        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        MemberMapper mdao = s.getMapper(MemberMapper.class);
        //System.out.println(mdao.queryById(1));
        //System.out.println(mdao.queryByInt(2));
        System.out.println(mdao.queryAll());
    }

    @Test
    public void tt() {
        MyHelper mh = new MyHelper();
        SqlSession s = mh.getSession();
        TeacherMapper tdao = s.getMapper(TeacherMapper.class);
        Teacher tea = tdao.queryById(1);


        System.out.println(tea.getName());
        System.out.println(tea.getId());

        StuClass sc = tea.getSclass();
        System.out.println(sc.getCid());
        System.out.println(sc.getCname());
    }
}
